package com.java.core.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

public class RequestUtils {
	public static Map<String, String> getParams(HttpServletRequest request) {
		Map<String, String> params = new HashMap<String, String>();
		Map<String, String[]> paramMap = request.getParameterMap();
		Set<String> keys = paramMap.keySet();
		for (String key : keys) {
			String[] values = paramMap.get(key);
			if (values.length > 1) {
				params.put(key, StringUtils.join(values, ","));
			} else if (values.length == 1) {
				params.put(key, values[0]);
			}
		}
		return params;
	}

	/**
	 * 获取IP地址
	 * 
	 * @param request
	 * @return
	 */
	public static String getIp(HttpServletRequest request) {
		return request.getRemoteHost();
	}
}
